#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stdlib.h>

int main()
{
    int rows,cols,entry;
    while (1) {
        std::cin>>rows>>cols;
        if(rows==0&&cols==0)
            break;
        std::cin>>entry;
        char *grid = new char[rows*cols];
        int *tr = new int[rows*cols];
        char str[1000];
        for(int i = 0; i < rows; i++)
        {
            std::cin>>str;
            memcpy(grid+i*cols, str, cols);
        }
        memset(tr, 0, 4*rows*cols);
        //start
        int x=entry-1,y=0;
        tr[y*cols+x]=1;
        int count = 0;
        bool exit = false;
        bool loop = false;
        int before,lo;
        while (1) {
            int nx,ny;
            switch (grid[y*cols+x]) {
            case 'W':
                nx=-1;ny=0;
                break;
            case 'E':
                nx=1;ny=0;
                break;
            case 'N':
                nx=0;ny=-1;
                break;
            default:
                //S
                nx=0;ny=1;
            }
            nx+=x;ny+=y;
            if(nx<0||nx==cols||ny<0||ny==rows){
                count = tr[y*cols+x];
                exit=true;
                break;
            }

            if(tr[ny*cols+nx]==0)
                tr[ny*cols+nx]=tr[y*cols+x]+1;
            else
            {
                loop=true;
                before=tr[ny*cols+nx]-1;
                lo=tr[y*cols+x]-before;
                break;
            }
            x=nx;y=ny;
        }
        //end
        if(exit)
            printf("%d step(s) to exit\n", count);
        if(loop)
            printf("%d step(s) before a loop of %d step(s)\n",before,lo);
        delete []grid;
        delete []tr;
    }
    return 0;
}
